{% extends 'starter.html' %}
{% load static %}
{% load customertags %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{% block title %}客户列表{% endblock title %}</title>
</head>

<body>
{% block page_header %}

        {% if tag == '1' %}
            公户信息

        {% else %}
            我的客户信息
        {% endif %}

{% endblock page_header %}
{% block content %}
    <form action="" class="form-inline pull-right" method="get">

        <div class="form-group">
            <select name="search_field" id="search_field" class="form-control">
                <option value="qq__contains">qq</option>
                <option value="name__contains">姓名</option>
            </select>

            <input type="text" class="form-control" id="" placeholder="请输入" name="keyword"
                   value="{{ keyword|default:'' }}">
        </div>
        <button type="submit" class="btn btn-success">搜索</button>
    </form>
    <a href="{% url 'sales:add_customer' %}">
        <button class="btn btn-success ">添加</button>
    </a>

    <form method="post" action="{% url 'sales:customer' %}" class="form-inline">

        <select name="action" class="form-control">

            {% show_pri_pub_option request %}
            <option value="bulk_delete">批量删除</option>
        </select>
        {% csrf_token %}

        <input type="submit" class="btn btn-primary btn-sm" value="应用">
        <p>{{ error_tip }}</p>
        <table class="table table-bordered table-striped table-hover">
            <!-- On rows -->
            <thead>
            <tr>
                <td class="">
                    <input type="button" class=" btn-success select_id" id="select_all" value="全选">
                </td>
                <td class="success">序号</td>
                <td class="info">qq号</td>
                <td class="success">姓名</td>
                <td class="info">性别</td>
                <td class="success">咨询课程</td>
                <td class="info">状态</td>
                {% ifequal  tag '0' %}
                    <td class="info">跟进记录</td>
                    <td class="success">销售</td>
                {% endifequal %}
                <td class="success">操作</td>
            </tr>
            </thead>
            <tbody>
            {% for customer in all_customers %}
                <tr>
                    <td><input type="checkbox" class="select_pk" name="pk" value="{{ customer.pk }}"></td>
                    <td>{{ forloop.counter }}</td>
                    <td>
                        {{ customer.qq }}
                    </td>
                    <td>{{ customer.name }}</td>
                    <td>{{ customer.get_sex_display }}</td>
                    <td>{{ customer.get_course_display }}</td>
                    <td>{{ customer.get_status_display }}</td>
                    {% ifequal tag '0' %}
                        <td><a href="{% url 'sales:consult_record' %}?customer_id={{ customer.pk }}">跟进详情</a></td>
                        <td>{{ customer.consultant.username }}</td>
                    {% endifequal %}
                    <td>
                        <a class="fa fa-2x fa-edit"
                           href="{% reverse_url 'sales:edit_customer' customer.pk request %}">
                        </a>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </form>
{% endblock %}
</body>

</html>
{% block paginator %}
    {{ page_html }}
{% endblock paginator %}

{% block custom_js %}
    <script>
        $(document).ready(function () {
            var field = '{{ search_field }}';  // 'name__contains'
            $('#search_field').val(field);
            $("#select_all").click(function () {
                $(".select_pk").attr('checked', true);
            })
        })
    </script>
{% endblock custom_js %}
